<include file="Public/header" />
<title></title>
<style>
	.yb{
		display:none;
	}
</style>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="form-article-add">
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>账册编码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
				<select name="zccode" class="select">
                    <option value="0" attr_type=0>---请选择---</option>
					<foreach name="book_list" item="vo">
						<option value="<{$vo.book_no}>" attr_type=<{$vo.type}> ><{$vo.name}>
						<if condition="$vo.type eq 1">
							(一般账册)
						</if>
						<if condition="$vo.type eq 2">
							(跨境账册)
						</if>
						</option>
					</foreach>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder=""  name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>条形码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input style="width: 120px;" type="text" class="input-text" value="" placeholder="" name="sn">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>销售单位：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="unit" data-toggle="" class="select">
                    <option value="0">---请选择---</option>
					<foreach name="unit_list" item="vo">
						<option value="<{$vo.unit_no}>"><{$vo.unit_name}></option>
					</foreach>
                </select>
				</span>
            </div>
        </div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>规格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" name="standard">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>销售单价：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="0" placeholder="" name="sell_price">
            </div>
        </div>
		<div class="row cl "  style="display:none;">
            <label class="form-label col-xs-4 col-sm-2">第二单位：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="unit_t" data-toggle="" class="select">
                    <option value="0">---请选择---</option>
					<foreach name="unit_list" item="vo">
						<option value="<{$vo.unit_no}>"><{$vo.unit_name}></option>
					</foreach>
                </select>
				
				</span>
            </div>
        </div>
		<div class="row cl "  style="display:none;">
            <label class="form-label col-xs-4 col-sm-2">第二单位规格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" name="unit_t_goods_spec">
            </div>
        </div>
		<div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>进价：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="0" placeholder="" name="purchase_price">
            </div>
        </div>
        <div class="row cl kj">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产销国：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="country" class="select">
                    <option value="0">---请选择---</option>
					<foreach name="country_list" item="vo">
						<option value="<{$vo.country_code}>"><{$vo.country_name}></option>
					</foreach>
                </select>
				</span>
            </div>
        </div>
        <div class="row cl kj">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>币制(进价)：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="trade_curr" class="select">
                    <option value="0">---请选择---</option>
					<foreach name="coin_list" item="vo">
						<option value="<{$vo.coin_code}>"><{$vo.coin_name}></option>
					</foreach>
                </select>
				</span>
            </div>
        </div>
		<div class="row cl kj" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>净重：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.net_weight}>" placeholder="" name="net_weight">
            </div>
        </div>
		<div class="row cl kj" >
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>毛重：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<{$result.gross_weight}>" placeholder="" name="gross_weight">
            </div>
        </div>
		
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="add()" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 新增</button>
                <button onClick="cancel()" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
<include file="Public/footer_js" />
<script>
	function cancel(){
        parent.layer.closeAll();
    }
	function add(){
		type=$(this).find('option:selected').attr('attr_type');
		
		name=$('input[name=name]').val();
		sn=$('input[name=sn]').val();
		
		zccode=$('select[name=zccode]').val();
		unit=$('select[name=unit]').val();
		standard=$('input[name=standard]').val();
		sell_price=$('input[name=sell_price]').val();
		
		if(name==''){
			layer.msg('请填写产品名称');
            return false;
		}
		if(sn==''){
			layer.msg('请填写产品条形码');
            return false;
		}
		if(zccode==0){
			layer.msg('请选择账册');
            return false;
		}
		if(unit==0){
			layer.msg('请选择销售单位');
            return false;
		}
		if(standard==''){
			layer.msg('请填写规格');
            return false;
		}
		if(sell_price==''){
			layer.msg('请填写销售价格');
            return false;
		}
		
		if(type=='1'){//一般账册
			unit_t=$('select[name=unit_t]').val();
			unit_t_goods_spec=$('input[name=unit_t_goods_spec]').val();
			if(unit_t==0){
				layer.msg('请选择第二单位');
				return false;
			}
			if(unit_t_goods_spec==''){
				layer.msg('请填写第二单位规格');
				return false;
			}
			$.post('__CONTROLLER__/confirm_add_two',{
				pro_status:type,//商品属性
				name:name,
				sn:sn,
				zccode:zccode,
				unit:unit,
				standard:standard,
				sell_price:sell_price,
				unit_t:unit_t,
				unit_t_goods_spec:unit_t_goods_spec,
			},function (msg){
				layer.msg(msg.data,function(){
					if(msg.flag==1){
						parent.location.reload();
						parent.layer.closeAll();
					}
				});
			},'json');
		}else{//保税/直邮
			purchase_price=$('input[name=purchase_price]').val();
			country=$('select[name=country]').val();
			trade_curr=$('select[name=trade_curr]').val();
			net_weight=$('input[name=net_weight]').val();
			gross_weight=$('input[name=gross_weight]').val();
			<!-- if(purchase_price==''){ -->
				<!-- layer.msg('请填写进价'); -->
				<!-- return false; -->
			<!-- } -->
			if(trade_curr==0){
				layer.msg('请选择币制');
				return false;
			}
			if(country==0){
				layer.msg('请选择产销国');
				return false;
			}
			if(net_weight==''){
				layer.msg('请填写净重');
				return false;
			}
			if(gross_weight==''){
				layer.msg('请填写毛重');
				return false;
			}
			$.post('__CONTROLLER__/confirm_add_two',{
				pro_status:type,//商品属性
				name:name,
				sn:sn,
				zccode:zccode,
				unit:unit,
				standard:standard,
				sell_price:sell_price,
				purchase_price:purchase_price,
				country:country,
				trade_curr:trade_curr,
				net_weight:net_weight,
				gross_weight:gross_weight,
			},function (msg){
				layer.msg(msg.data,function(){
					if(msg.flag==1){
						parent.location.reload();
						parent.layer.closeAll();
					}
				});
			},'json');
		}
		
	}
$(function(){
	$('select[name=zccode]').change(function(){
		type=$(this).find('option:selected').attr('attr_type');
		if(type=='1'){//一般账册
			$('.yb').css('display','block');
			$('.kj').css('display','none');
		}else{//保税/直邮
			$('.yb').css('display','none');
			$('.kj').css('display','block');
		}
	})
})
</script>
</body>
</html>